import requests

url = "https://gitee.com/yao_huaiyu/projects"
h = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
# 未加cookie
html = requests.get(url, headers=h)
with open('no_cookie.html', 'w', encoding='utf-8') as f:
    f.write(html.content.decode())
# 加了cookie（网页上登录，再访问url）
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
    'Cookie': 'user_locale=zh-CN; oschina_new_user=false; __guid=120207262.1265201093120505000.1607044756697.4126; tz=Asia%2FShanghai; Hm_lvt_24f17767262929947cc3631f99bfd274=1607044758; sajssdk_2015_cross_new_user=1; remote_way=ssh; monitor_count=17; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%227554853%22%2C%22first_id%22%3A%221762b54fad51d2-0ad3bad766b819-376b4502-2073600-1762b54fad6a51%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%221762b54fad51d2-0ad3bad766b819-376b4502-2073600-1762b54fad6a51%22%7D; Hm_lpvt_24f17767262929947cc3631f99bfd274=1607046618; gitee-session-n=KzFJNFJQUzh0TkFFWTByaDdCMWRsZE9iWVJPSi9xdHBhL1FPSXozcVlPUHpRVUdwT0dLeUZyanFuNHcza1Eza1N6VFkyOGtpdGlEWlRpdVRpeVd0NVpsQzI4cE1DZzdUTjlkYXp6VC82d2M5ZUpvcXBaVTBwQ0luVjNGMktDRVMwUkg5bVl1UFIxZUVFTzV4U21jZlFzSDJ2N2hmOEpjYVpLRFJBN1R2ZjNIbTZ6UFJTRTlqMUhJaGovVDdlMXBHWHBCZW9zcDhnbWo1UG9acHN1YkpFTnEzYWNCSE0wUFBmWkdWcXpwU0RBWjJwQStHV0V2aDhoTktuVUJMa29BWlBLTVNlVlExY05Za2xrbjVHanZZaU1SZm5SR0h0Q1kyTi9pSU95clBWY05GNkN0UGNMb0xUZDVFZVVSVVdrdGQ3R05nSzNZejZZZE9CNmNhQ1J0bEZDN1B5ZlhPQnlGaXRnYzVWM2pna3dzPS0tUGRNYURaL1FUcHFVNVcrblNySzVpZz09--f68903134cd51b31113abe415107cef8b6bb59df'
}
html = requests.get(url, headers=header)
with open('has_cookie.html', 'w', encoding='utf-8') as f:
    f.write(html.content.decode())
